

package webdev.customlib.slidingmenu;

import webdev.fragment.LeftNavigationFragment;
import webdev.fragment.SearchNavigationFragment;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

import dev.danang.R;

/**
 * @author Truong.le
 *
 */
public class BaseActivity extends SlidingFragmentActivity {
	private static final String TAG = BaseActivity.class.getSimpleName();
    public LeftNavigationFragment mLeftNavigationFragment;
    public SearchNavigationFragment mSearchNavigationFragment;
    public SlidingMenu slidingMenu;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		// this.broadcast = broadcast;
		
//        if (Utils.hasHoneycomb() == false) {
//            getSupportActionBar().hide();
//        }
        slidingMenu = getSlidingMenu();
        slidingMenu.setShadowWidthRes(R.dimen.shadow_width);
        slidingMenu.setShadowDrawable(R.drawable.shadow);
        slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        slidingMenu.setFadeDegree(0.0f);
        slidingMenu.setBehindScrollScale(0);
        slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);

        // set the Behind View
        setBehindContentView(R.layout.menu_frame);
        if (savedInstanceState == null) {
            // Left navigation
            mLeftNavigationFragment = new LeftNavigationFragment().newInstance("");
            getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame, mLeftNavigationFragment).commit();

            slidingMenu.setSecondaryMenu(R.layout.menu_frame_two);
            slidingMenu.setSecondaryShadowDrawable(R.drawable.shadowright);
            // Search navigation
            mSearchNavigationFragment = new SearchNavigationFragment();
            getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame_two, mSearchNavigationFragment).commit();
        } else {
            mLeftNavigationFragment = (LeftNavigationFragment) this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
            mSearchNavigationFragment = (SearchNavigationFragment) this.getSupportFragmentManager().findFragmentById(R.id.menu_frame_two);
        }
        
        
    }
	
	@Override
	protected void onDestroy() {
		System.gc();
		System.runFinalization();
		super.onDestroy();
	}

	@Override
	public void finish() {
		super.finish();
	}

	@Override
	public void finishActivity(int requestCode) {
		super.finishActivity(requestCode);
	}
    @Override
    protected void onPause() {
    	super.onPause();
    	Log.i(TAG, "onPause");
    }
    @Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            toggle();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // getSupportMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    /**
     * This method is used to init all variable members
     * @author thangtc
     */
    public void init(){
    	
    }

    /**
     * This method is used to set value for members
     * @author thangtc
     */
    public void setValue()
    {
    	
    }

    /**
     * This method is used to set event for members
     * @author thangtc
     */
    public  void setEvent()
    {
    	
    }
	/*@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK)
		{
             onBackPressed();
         }
		return super.onKeyDown(keyCode, event);
	}*/
	public void onBackPressed() {
        Log.d("CDA", "onBackPressed Called");
        super.onBackPressed();
    }
}
